<script>
import Vue from 'vue';
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
	onLaunch: function () {
		console.log('App Launch');
		let that = this;
		setTimeout(() => {
			uni.getSystemInfo({
				success: function (e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 60;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 55;
					}
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = uni.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					console.log('custom', custom, e.statusBarHeight);
					Vue.prototype.CustomBar = e.platform == 'ios' ? 44 + e.statusBarHeight : 48 + e.statusBarHeight;
					// Vue.prototype.CustomBar = custom.height + e.top;

					// #endif

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
					Vue.prototype.windowHeight = e.windowHeight;
					/* 计算一下 宽高比例 */
					that.SET_CustomBar(Vue.prototype.CustomBar);
					that.SET_StatusBar(Vue.prototype.StatusBar);
					that.SET_menuBtnWidth(custom.width);
				}
			});
		});
		this.getUserinfo();
		this.getsysInfo();
		this.getShareInfo();
		this.getWxminprogram();
		if (!this.currentLocation && !this.currentProvince) {
			this.getLoaction();
		}
	},
	computed: {
		...mapState(['currentLocation', 'currentProvince'])
	},
	onShow: function () {
		console.log('App Show');
	},
	onHide: function () {
		console.log('App Hide');
	},
	methods: {
		...mapMutations([
			'SET_CustomBar',
			'SET_StatusBar',
			'SET_menuBtnWidth',
			'updateIsLogin',
			'SET_SYSINFO',
			'SET_SHAREINFO',
			'SET_KfInfo',
			'SET_CURRENTLOCATION',
			'SET_ShopWxConfig'
		]),
		...mapActions(['getUserInfo', 'SetCarTotal']),
		getUserinfo() {
			this.getUserInfo().then(da => {
				this.updateIsLogin(true);
			});
		},
		getsysInfo() {
			this.$postAction(this.$api.getsysInfo, null, {
				custom: {
					ShowLoading: false
				}
			}).then(da => {
				wx.setNavigationBarTitle({
					title: da.data.applet_info.name
				});
				this.SET_SYSINFO(da.data);
			});
		},
		getShareInfo() {
			this.$postAction(this.$api.shareInfo, null, {
				custom: {
					ShowLoading: false
				}
			}).then(da => {
				if (da.code == 0) {
					this.SET_SHAREINFO(da.data);
				}
			});
		},
		//获取客服信息
		// getkf() {
		// 	this.$postAction(this.$api.getkf).then(da => {
		// 		if (da.code == 0) {
		// 			this.SET_KfInfo(da.data);
		// 		}
		// 	});
		// },
		getLoaction() {
			this.$postAction(this.$api.get_address).then(da => {
				if (da.code == 0) {
					this.SET_CURRENTLOCATION(da.data);
				}
			});
		},
		/* 获取满减信息 */
		getWxminprogram() {
			this.$postAction(this.$api.get_wxminprogram).then(da => {
				if (da.code == 0) {
					this.SET_ShopWxConfig(da.data);
				}
			});
		}
	}
};
</script>
<style>
:root {
	--nav-bg: #ff453a;
	--nav-color: #ffffff;
}
</style>
<style lang="scss">
/*每个页面公共css */
@import '@/uni_modules/uview-ui/index.scss';
// @import 'colorui/main.css';
button,
image,
input,
label,
navigator,
scroll-view,
swiper,
textarea,
view {
	box-sizing: border-box;
}

page {
	background-color: #f4f4f4;
	height: 100%;
	width: 100%;
}

.o {
	border-radius: 5000rpx;
}

.box,
.box-o {
	background-color: #fff;
	margin-left: 20rpx;
	margin-right: 20rpx;
	margin-top: 20rpx;
	padding: 20rpx;
}

.box-no-color,
.box-o {
	border-radius: 16rpx;
}

.box-no-color {
	margin-left: 20rpx;
	margin-right: 20rpx;
	margin-top: 20rpx;
	padding: 20rpx;
}

.box-no-mg {
	padding: 20rpx;
}

.box-no-mg,
.box-no-mg-pd {
	background-color: #fff;
	border-radius: 40rpx;
}

.bgimg {
	align-items: center;
	background-position: 50%;
	background-size: cover;
	color: #fff;
	display: inline-flex;
	font-size: 1.5em;
	font-variant: small-caps;
	justify-content: center;
	margin: 0;
	padding: 0;
	position: relative;
	text-align: center;
	vertical-align: middle;
	white-space: nowrap;
}

.bgimg.xs {
	height: 20rpx;
	width: 20rpx;
}

.bgimg.sm {
	height: 32rpx;
	width: 32rpx;
}

::-webkit-scrollbar {
	display: none;
}

.t-red {
	color: #c60c0c;
}

.t-green {
	color: #2a7e35;
}

.t-grey {
	color: #999;
}

.t-dark {
	color: #666;
}

.t-white {
	color: #fff;
}

.t-blue {
	color: #2e6490;
}

.t-blue-thin {
	color: #1296db;
}

.t-yellow {
	color: #e9cd6a;
}

.w100 {
	width: 100%;
}

.h100 {
	height: 100%;
}
.u-page {
	position: relative;
	height: 100vh;
	width: 100vw;
	overflow: hidden;
	font-size: 28upx;
	padding-bottom: calc(env(safe-area-inset-bottom) / 2);
	&.fullpage {
		overflow: visible;
	}
	.u-flex-sub.main {
		min-height: 0;
		overflow: auto;
	}
}

.link {
	color: #427cf5;
}
</style>
<style lang="scss">
.text-cut {
	text-overflow: ellipsis;
	white-space: nowrap;
	overflow: hidden;
}
.main {
	margin-left: 28upx;
	margin-right: 28upx;
}
.card {
	background: #fff;
	border-radius: 12upx;
}
.u-button--info {
	font-size: 28upx !important;
	&.u-button--plain {
		color: #969696;
		background: #fafafa;
		border: 1px solid #969696;
	}
}
.u-button--success {
	border: none !important;
	background: linear-gradient(90deg, #ff8173 0%, #ff3543 100%);
	height: 82upx !important;
	font-size: 28upx !important;
	color: #fff !important;
	&.u-button--plain {
		background: none;
		color: var(--nav-bg) !important;
		border: 1px solid var(--nav-bg) !important;
	}
}
.text-primary {
	color: var(--nav-bg);
}
uni-image {
	max-width: 100%;
}
.imgbox {
	image {
		display: block;
		height: 100%;
		width: 100%;
	}
}
</style>
